﻿using System;
using System.Collections.Generic;
using System.Text;
using LeanBoard.Models;

namespace LeanBoard.HtmlBuilders
{
    public class ItemHtmlBuilder
    {
        public string BuildHtml(IList<Item> items)
        {
            StringBuilder sb = new StringBuilder();

            foreach (Item item in items)
            {
                string headerClass = GetItemHeaderCoulour(item);
                string bodyClass = GetItemBodyCoulour(item);
                sb.Append("<li class=\"").Append("item " +bodyClass).Append("\"").Append("id=\"").Append(item.Id).Append("\"").Append(">").Append(Environment.NewLine);
                sb.Append("<div class=\"").Append("itemHeader idHeader " + headerClass).Append("\">").Append(item.Id).Append("</div>").Append(Environment.NewLine); 
                sb.Append("<div class=\"").Append("itemHeader priorityHeader "+headerClass).Append("\">").Append("P" + item.Priority).Append("</div>").Append(Environment.NewLine); 
                sb.Append("<div class=\"crResponsible "+bodyClass+" \">").Append(item.DevResponsible).Append("</div>").Append(Environment.NewLine); 
                //sb.Append("<div class=\"crQAResponsible\">").Append(item.QaResponsible).Append("</div>").Append(Environment.NewLine); 
                sb.Append("<div class=\"crTitle " + bodyClass + "\">").Append(item.Title).Append("</div>").Append(Environment.NewLine);
                sb.Append("<div class=\"unid\">").Append(item.Unid).Append("</div>");
                sb.Append("</li>").Append(Environment.NewLine); 
                sb.Append(Environment.NewLine);
            }

            return sb.ToString();
        }

        private static string GetItemHeaderCoulour(Item item)
        {
            if (item.ItemType == "Change") return "changeHeader";
            if (item.ItemType == "Analysis") return "analysisHeader";
            if (item.ItemType == "Defect") return "defectHeader";
            if (item.ItemType == "Suggestion") return "suggestionHeader";
            if (item.ItemType == "Internal") return "internalQualityProblemHeader";
            if (item.ItemType == "Support") return "supportRequestHeader";

            return string.Empty;
        }

        private static string GetItemBodyCoulour(Item item)
        {
            if (item.ItemType == "Change") return "changeBody";
            if (item.ItemType == "Analysis") return "analysisBody";
            if (item.ItemType == "Defect") return "defectBody";
            if (item.ItemType == "Suggestion") return "suggestionBody";
            if (item.ItemType == "Internal") return "internalQualityProblemBody";
            if (item.ItemType == "Support") return "supportRequestBody";

            return string.Empty;
        }

        public string BuildStandupItems(ItemsCollection items)
        {
            StringBuilder sb = new StringBuilder();

            List<Item> forStandup = new List<Item>();


            forStandup.AddRange(items.Development);
            forStandup.AddRange(items.ReadyForCodeReview);
            forStandup.AddRange(items.CodeReview);
            forStandup.AddRange(items.ReadyForApporval);
            forStandup.AddRange(items.Testing);


            foreach (Item item in forStandup)
            {
                sb.Append("<div style=\"width:1040px;height:500px;overflow:hidden;\">");
                sb.Append("<div class=\"description\">");
                sb.Append("<span class=\"h\">CR:</span>");
                sb.Append("<span class=\"v\">").Append(item.Id).Append("</span>");
                sb.Append("&nbsp;&nbsp;&nbsp;");
                sb.Append("<span class=\"h\">Priority:</span>");
                sb.Append("<span class=\"v\">").Append(item.Priority).Append("</span>");
                sb.Append("<div style=\"float:right\">");
                sb.Append("<img src=\"").Append("../../Client/Profiles/KacperRyniec.jpg").Append("\" alt=\"\" width=\"178\" height=\"178\">");
                sb.Append("</div>");
                sb.Append("<div class=\"m\">");
                sb.Append("<span class=\"h\">Developed by:</span>");
                sb.Append("<span class=\"v\">").Append(item.DevResponsible).Append("</span>");
                sb.Append("</div>");
                sb.Append("<div class=\"m\">");
                sb.Append("<span class=\"h\">State:</span>");
                sb.Append("<span class=\"v\">").Append(item.Status).Append("</span>");
                sb.Append("</div>");
                sb.Append("<div class=\"m\">");
                sb.Append("<span class=\"h\">Title:</span>");
                sb.Append("<span class=\"v\">").Append(item.Title).Append("</span>");
                sb.Append("</div>");
                sb.Append("</div>");
                sb.Append("</div>");
                sb.Append(Environment.NewLine);
            }

            return sb.ToString();
        }
    }
}